﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using WF_Business;
using ExtBusiness;

namespace ExtBusiness
{
    public class WebOtherManager
    {
        /// <summary>
        /// 返回所有信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetOther(string strId)
        {
            string strSql = string.Format(@"select * from st_other where id='{0}'", strId);
           
            DataTable dt = null;
            SysParams.OAConnection().RunSql(strSql, out dt);
            return dt;
        }

        /// <summary>
        /// 返回所有信息
        /// </summary>
        /// <param name="strTitle">标题</param>
        /// <param name="strType">类型</param>
        /// <returns></returns>
        public DataTable GetOther(string strSmallType, string strType)
        {
            string strSql = string.Format(@"select * from st_other where 
                    SMALLTYPE='{0}' and TYPE='{1}'", strSmallType, strType);

            DataTable dt = null;
            SysParams.OAConnection().RunSql(strSql, out dt);
            return dt;
        }

        /// <summary>
        /// 返回所有信息的个数
        /// </summary>
        /// <param name="strSmallType">小类</param>
        /// <param name="strType">类型</param>
        /// <returns></returns>
        public string GetCount(string strSmallType, string strType)
        {
            string strCount = "";
            if (!string.IsNullOrEmpty(strSmallType) && !string.IsNullOrEmpty(strType))
            {
                string strSql = string.Format(@"select count(*) from st_other where 
                    SMALLTYPE='{0}' and TYPE='{1}'", strSmallType, strType);
                strCount = SysParams.OAConnection().GetValue(strSql);
            }
            return strCount;
        }

        /// <summary>
        /// 修改是否在首页通知
        /// </summary> 
        /// <param name="memu_title"></param>
        /// <returns></returns>
        public static void UpdateIsNotice()
        {
            string strSql = "update st_other set is_notice='0' where is_notice='1'";

            SysParams.OAConnection().RunSql(strSql);
        }

        /// <summary>
        /// 增加信息
        /// </summary>
        /// <param name="strTitle">The STR title.</param>
        /// <param name="strType">Type of the STR.</param>
        /// <param name="strSmallTYpe">The STR small T ype.</param>
        /// <param name="iNotice">The i notice.</param>
        /// <param name="strContent">Content of the STR.</param>
        public static void InsertManage(string strTitle, string strType, string strSmallType,
            string iNotice,string strContent)
        {
            string strSql = string.Format(@"insert into st_other(TITLE,SMALLTYPE,CONTENT,TYPE,IS_NOTICE) 
                VALUES ('{0}','{3}',:conParam,'{1}','{2}')", strTitle, strType, iNotice, strSmallType);

            IDataParameter[] idp = new OracleParameter[1];
            idp[0] = new OracleParameter(":conParam", OracleType.Clob);
            idp[0].Value = strContent;
            SysParams.OAConnection().RunSql(strSql, ref idp);
        }

        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="strSmallType">Type of the STR small.</param>
        /// <param name="strType">Type of the STR.</param>
        /// <param name="iNotice">The i notice.</param>
        /// <param name="strContent">Content of the STR.</param>
        public static void UpdateManages(string strSmallType, string strType, 
            string iNotice, string strContent)
        {
            string strSql = string.Format(@"update st_other set CONTENT=:conParam ,IS_NOTICE='{2}' where 
                    SMALLTYPE='{0}' and TYPE='{1}'", strSmallType, strType, iNotice);

            System.Data.IDataParameter[] idp = new System.Data.OracleClient.OracleParameter[1];
            idp[0] = new OracleParameter(":conParam", OracleType.Clob);
            idp[0].Value = strContent;
            SysParams.OAConnection().RunSql(strSql, ref idp);
        }

        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="memu_title"></param>
        /// <returns></returns>
        public static void UpdateManagesId(string strId, string iNotice, string strSmallType,
            string strContent, string strTitle)
        {
            string strSql = string.Format(@"update st_other set CONTENT=:conParam ,IS_NOTICE='{1}',
                TITLE='{2}',SMALLTYPE='{3}' where id='{0}'", strId, iNotice, strTitle,strSmallType);

            System.Data.IDataParameter[] idp = new System.Data.OracleClient.OracleParameter[1];
            idp[0] = new OracleParameter(":conParam", OracleType.Clob);
            idp[0].Value = strContent;
            SysParams.OAConnection().RunSql(strSql, ref idp);
        }
    }
}
